import { cloud } from '@hw-agconnect/cloud-server';
import { location_info } from './location_info'; // location是Server Model

// default是location对象类型使用的存储区名
// 创建链接数据库的句柄
const collection = cloud.database({ zoneName: 'default' }).collection(location_info);


export class LocationInfoObj {
  query() {
    return collection.query().get();
  }

  upset(locationInfos: location_info[]) {
    return new Promise((resolve, reject) => {
      collection.upsert(locationInfos.map(lInfo => location_info.parseFrom(lInfo)))
        .then(result => resolve({ result }))
        .catch(err => reject(err))
    });
  }
}
